﻿namespace WLCompiler.Helpers.SemanticAnalyze
{
    public abstract class UniqueObject   
    {
        protected UniqueObject() {}
            
        protected UniqueObject(string id)
        {
            Id = id;
        }

        public string Id { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            var other = obj as UniqueObject;
            if (other == null)
            {
                return false;
            }

            return Id == other.Id;
        }

        public bool Equals(UniqueObject other)
        {
            if ((object)other == null)
            {
                return false;
            }

            return Id == other.Id;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        public static bool operator == (UniqueObject firstOne, UniqueObject secondOne)
        {
            if (ReferenceEquals(firstOne, secondOne))
            {
                return true;
            }

            if ((object)firstOne == null || (object)secondOne == null)
            {
                return false;
            }

            return firstOne.Id == secondOne.Id;
        }

        public static bool operator != (UniqueObject firstOne, UniqueObject secondOne)
        {
            return !(firstOne == secondOne);
        }
    }
}
